﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame4
{
    class Player_InitialState: State
    {
        private static Player_InitialState instance;

        private Player_InitialState()
        {
            base.Name = "InitialState";
        }

        public override void enter(AIObject aiObject)
        {
            AIPlayer aiPlayer = (AIPlayer)aiObject;
            Player player = (Player)aiPlayer.Player;
            player.Blinking = true;
            EventEmitter.getInstance().registerMessage(50000000, player.Id, player.Id, Message.MessageType.msg_disableBlinking);
        }

        public static Player_InitialState getInstance()
        {
            if (instance == null)
                instance = new Player_InitialState();
            return instance;
        }

        public override void execute(AIObject aiObject)
        {
            AIPlayer aiPlayer = (AIPlayer)aiObject;
            Player player = (Player)aiPlayer.Player;
            GameInfo gameInfo = GameInfo.getInstance();
            EventEmitter.getInstance().registerMessage(0, player.Id, player.Id, Message.MessageType.msg_stop);
        }

        public override void exit(AIObject aiObject)
        {

        }

        public override Boolean onMessage(AIObject aiObject, Message message)
        {
            Boolean correct = false;
            switch (message.Type)
            {
                case Message.MessageType.msg_stop:
                    {
                        aiObject.StateMachine.changeState(Player_StopState.getInstance());
                        correct = true;
                        break;
                    }
                case Message.MessageType.msg_disableBlinking:
                    {
                        AIPlayer aiPlayer = (AIPlayer)aiObject;
                        Player player = (Player)aiPlayer.Player;
                        player.Blinking = false;
                        correct = true;
                        break;
                    }
            }
            return correct;
        }
    }
}